@extends('layouts.master3')
<?php
use App\Utils;
?>
@section('title')
    {{"千里码-技能树"}}
@stop
@section("css")
    <link rel="stylesheet" type="text/css" href="/css/tree.css">
    <link rel="stylesheet" href="/css/index.css">

    <style>
        div.panel {
            width: 150px;
            margin: auto;
        }
    </style>
@endsection

@section('content')
    <div class="contain main">

        <!-- 左边D3-->
        <div class="task_left pull-left">
            <div class="d3"></div>

        </div>
    </div>

    <div class="panel">
        <button class="save">
            保存布局
        </button>
        <input type="hidden" name="_token" value="{{csrf_token()}}">
        <p class="result"></p>
    </div>
    <!-- /.container -->
@endsection
@section('js')
    <script>
        $("button.save").click(function() {
            var token=$("input[name='_token']").val();
            var ids = [], xs = [], ys = [];
            for(var i = 0; i < nodes.length; i++) {
                ids[i] = nodes[i].id;
                xs[i] = nodes[i].x;
                ys[i] = nodes[i].y;
            }
            $.ajax({
                type: 'post',
                data:{
                    ids:ids.join(','),
                    xs:xs.join(','),
                    ys:ys.join(','),
                    _token:token
                },
                success:function(data) {
                    $("p.result").text(data);
                }
            });
        });
        window['nodes']=[
            <?php
            foreach($tasks as $task)
            {
                if($task->x!=0)
                {
                    $str='fixed: true,x: '.$task->x.',y: '.$task->y."";
                }
                else $str="";
                if($solve[$task->id]==1)
                    echo "{id:".$task->id.",name: '".$task->title."', reflexive: false,".$str."},\n";
                else if($solve[$task->id]==2)
                    echo "{id:".$task->id.",name: '".$task->title."', reflexive: true,".$str."},\n";
                else
                    echo "{id:-1,name: 'none', reflexive: true,fixed: true,x: -100,y: -100},\n";
            }
            ?>

        ];
        window['links']=[
            <?php
            foreach($links as $link)
            {
                if($solve[$link->first]!=1)continue;
                echo "{source: nodes[".($link->first-1)."], target: nodes[".($link->second-1)."], left: false, right: true },\n";
            }
            ?>

        ];

    </script>
    <script src="/js/d3.js"></script>
    <script src="/js/tree_edit.js"></script>
    <script src="/js/local.min.js"></script>
    <script src="/js/jquery.mCustomScrollbar.js"></script>
    <script src="/js/jquery.mousewheel.min.js"></script>
@endsection
